/*
 * Copyright 2010 Mttang.com All right reserved. This software is the confidential and proprietary information of
 * Mttang.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Mttang.com.
 */
package com.mttang.util;

import java.util.List;

import com.mttang.sys.dto.TreeDTO;

/**
 * 类TreeInfo.java的实现描述：TODO 类实现描述
 * 
 * @author 郑斌 2010-6-9 下午03:10:17
 */
public class TreeInfo {

    public String getTreeStr(List<TreeDTO> rcdList){
        StringBuilder strBuilder = new StringBuilder();
        for(TreeDTO dto:rcdList){
            int id = dto.getId();
            if(isParentNode(rcdList,id)){
                strBuilder.append("d.add(").append(dto.getId()).append(",").append(dto.getPid()).append(",'").append(dto.getName()).append("','','','','../img/folder.gif','','','');\r\n");
            }
            else{
                strBuilder.append("d.add(").append(dto.getId()).append(",").append(dto.getPid()).append(",'").append(dto.getName()).append("','','','','../img/page.gif','','','');\r\n");
            }
        }
        return strBuilder.toString();
        
    }
    
    private boolean isParentNode(List<TreeDTO> rcdList, int id){
        
        boolean isParentNode = false;
        
        for(TreeDTO dto:rcdList){
            int pid = dto.getPid();
            if(id == pid){
                isParentNode = true;
                break;
            }
        }
        return isParentNode;
    }
}
